load("//rs/tests:common.bzl", "GRAFANA_RUNTIME_DEPS", "MAINNET_ENV", "STATESYNC_TEST_CANISTER_RUNTIME_DEPS", "UNIVERSAL_CANISTER_ENV", "UNIVERSAL_CANISTER_RUNTIME_DEPS", "XNET_TEST_CANISTER_RUNTIME_DEPS")
load("//rs/tests:system_tests.bzl", "system_test", "system_test_nns")

package(default_visibility = ["//rs:system-tests-pkg"])

exports_files([
    "memory_safety.wasm",
])

system_test_nns(
    name = "global_reboot_test",
    env = UNIVERSAL_CANISTER_ENV | {
        "XNET_TEST_CANISTER_WASM_PATH": "$(rootpath //rs/rust_canisters/xnet_test:xnet-test-canister)",
    },
    tags = [
        "long_test",  # since it takes longer than 5 minutes.
    ],
    runtime_deps = XNET_TEST_CANISTER_RUNTIME_DEPS + UNIVERSAL_CANISTER_RUNTIME_DEPS,
    deps = [
        "//rs/registry/subnet_type",
        "//rs/rust_canisters/canister_test",
        "//rs/rust_canisters/dfn_candid",
        "//rs/rust_canisters/xnet_test",
        "//rs/tests/driver:ic-system-test-driver",
        "@crate_index//:anyhow",
        "@crate_index//:candid",
        "@crate_index//:ic-management-canister-types",
        "@crate_index//:itertools",
        "@crate_index//:slog",
        "@crate_index//:tokio",
    ],
)

system_test(
    name = "memory_safety_test",
    compile_data = [
        "memory_safety.wasm",
    ],
    tags = [
        "long_test",
    ],
    deps = [
        "//rs/registry/subnet_type",
        "//rs/tests/driver:ic-system-test-driver",
        "//rs/types/base_types",
        "//rs/types/types",
        "@crate_index//:anyhow",
        "@crate_index//:candid",
        "@crate_index//:ic-agent",
        "@crate_index//:ic-utils",
        "@crate_index//:rand",
        "@crate_index//:rand_chacha",
        "@crate_index//:slog",
        "@crate_index//:tokio",
    ],
)

system_test_nns(
    name = "rejoin_test",
    env = UNIVERSAL_CANISTER_ENV,
    tags = [
        "long_test",
    ],
    runtime_deps =
        GRAFANA_RUNTIME_DEPS +
        UNIVERSAL_CANISTER_RUNTIME_DEPS,
    deps = [
        "//rs/registry/subnet_type",
        "//rs/tests/driver:ic-system-test-driver",
        "//rs/tests/message_routing/rejoin_test_lib",
        "//rs/types/types",
        "@crate_index//:anyhow",
    ],
)

system_test_nns(
    name = "rejoin_test_large_state",
    enable_head_nns_variant = False,  # only run this test with the mainnet NNS canisters.
    env = UNIVERSAL_CANISTER_ENV | {
        "STATESYNC_TEST_CANISTER_WASM_PATH": "$(rootpath //rs/rust_canisters/statesync_test:statesync-test-canister)",
    },
    tags = [
        "system_test_large",
    ],
    test_timeout = "eternal",
    runtime_deps =
        GRAFANA_RUNTIME_DEPS +
        STATESYNC_TEST_CANISTER_RUNTIME_DEPS +
        UNIVERSAL_CANISTER_RUNTIME_DEPS,
    deps = [
        "//rs/registry/subnet_type",
        "//rs/tests/driver:ic-system-test-driver",
        "//rs/tests/message_routing/rejoin_test_lib",
        "//rs/types/types",
        "@crate_index//:anyhow",
    ],
)

system_test_nns(
    name = "state_sync_malicious_chunk_test",
    enable_head_nns_variant = False,  # only run this test with the mainnet NNS canisters.
    env = UNIVERSAL_CANISTER_ENV | {
        "STATESYNC_TEST_CANISTER_WASM_PATH": "$(rootpath //rs/rust_canisters/statesync_test:statesync-test-canister)",
    },
    tags = [
        "system_test_large",
    ],
    test_timeout = "eternal",
    uses_guestos_img = False,
    uses_guestos_malicious_img = True,
    runtime_deps = GRAFANA_RUNTIME_DEPS + STATESYNC_TEST_CANISTER_RUNTIME_DEPS + UNIVERSAL_CANISTER_RUNTIME_DEPS,
    deps = [
        "//rs/registry/subnet_type",
        "//rs/tests/driver:ic-system-test-driver",
        "//rs/tests/message_routing/rejoin_test_lib",
        "//rs/types/types",
        "@crate_index//:anyhow",
        "@crate_index//:slog",
    ],
)

system_test(
    name = "queues_compatibility_test",
    env = MAINNET_ENV,
    runtime_deps = [
        "//rs/replicated_state:replicated_state_test_binary",
    ],
    deps = [
        "//rs/recovery",
        "//rs/tests/driver:ic-system-test-driver",
        "//rs/types/types",
        "@crate_index//:anyhow",
        "@crate_index//:serde",
        "@crate_index//:serde_json",
        "@crate_index//:slog",
        "@crate_index//:tempfile",
    ],
)
